<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
include '../operations/connection.php';	

$idAssets=$_REQUEST['idAssets'];
$nameAssets=rawurldecode($_REQUEST['nameAssets']);
$countAssets=$_REQUEST['countAssets'];
$notuseAssets=$_REQUEST['notuseAssets'];
$stockAssets=$_REQUEST['stockAssets'];

$valueAssets=str_replace(",", "", $_REQUEST['valueAssets']);
$placeAssets=rawurldecode($_REQUEST['placeAssets']);

$noteAssets=rawurldecode($_REQUEST['noteAssets']);
$memoAssets=rawurldecode($_REQUEST['memoAssets']);

$groupAssets=$_REQUEST['groupAssets'];
$typeAssets=$_REQUEST['typeAssets'];
$idgroupAssets=$_REQUEST['idgroupAssets'];
$idtypeAssets=$_REQUEST['idtypeAssets'];

$result=mysql_query("SELECT * FROM assets a WHERE a.`name`='".$nameAssets."' AND a.`type`='".$typeAssets."' AND a.`group`='".$groupAssets."';");
$i=0;
while ($r=mysql_fetch_array($result)){
	$i++;
}
if($placeAssets!=""){
	$kq=mysql_query("SELECT * FROM assets_place c WHERE c.`name`='$placeAssets';");
	if(mysql_num_rows($kq)<=0)
		mysql_query("INSERT INTO `assets_place` (`name`) VALUES ('$placeAssets')");
}
//echo "SELECT * FROM assets a WHERE a.`name`='".$nameAssets."' AND a.`type`='".$typeAssets."' AND a.`group`='".$groupAssets."';";
if($i==0)
	mysql_query("UPDATE `assets` SET `name`='".$nameAssets."', `count`='".$countAssets."', `stock`='".$stockAssets."', `value`='".$valueAssets."', `place`='".$placeAssets."', `notuse`='".$notuseAssets."', `note`='".$noteAssets."',`memo`='".$memoAssets."', `group`='".$groupAssets."', `type`='".$typeAssets."',creater='".$_SESSION['IDEmployee']."', datetime=NOW() WHERE (`id`='".$idAssets."')");
else{
	if($idgroupAssets==$groupAssets && $idtypeAssets==$typeAssets){
		mysql_query("UPDATE `assets` SET `name`='".$nameAssets."', `count`='".$countAssets."', `stock`='".$stockAssets."', `value`='".$valueAssets."', `place`='".$placeAssets."', `notuse`='".$notuseAssets."', `note`='".$noteAssets."',`memo`='".$memoAssets."', `group`='".$groupAssets."', `type`='".$typeAssets."',creater='".$_SESSION['IDEmployee']."', datetime=NOW() WHERE (`id`='".$idAssets."')");
	}else{
		mysql_query("UPDATE `assets` SET `count`=`count`+'".$countAssets."', `stock`=`stock`+'".$stockAssets."', `value`='".$valueAssets."', `place`='".$placeAssets."', `notuse`=`notuse`+'".$notuseAssets."',`group`='".$groupAssets."',creater='".$_SESSION['IDEmployee']."', datetime=NOW() WHERE `name`='".$nameAssets."' AND `type`='".$typeAssets."' AND `group`='".$groupAssets."';");
		mysql_query("DELETE FROM `assets` WHERE `id`=".$idAssets);
	}
}
//echo $i;
//echo "UPDATE `assets` SET `name`='".$nameAssets."', `count`='".$countAssets."', `stock`='".$stockAssets."', `notuse`='".$notuseAssets."', `note`='".$noteAssets."', datetime=NOW() WHERE (`id`='".$idAssets."')";
mysql_close($connection);
?>